﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace domain
{
    public class AccountDao : KbSqlConnection
    {
        public int temp(int a)
        {
            this.Initialize(DomainResource.TempProcedure);
            this.SqlDataAdapter.SelectCommand.Parameters.Add(new SqlParameter("@input", SqlDbType.Int));
            this.SqlDataAdapter.SelectCommand.Parameters["@input"].Value = (a);
            this.SqlDataAdapter.SelectCommand.Parameters.Add(new SqlParameter("@output", SqlDbType.Int));
            this.SqlDataAdapter.SelectCommand.Parameters["@output"].Direction = ParameterDirection.Output;
            this.SqlDataAdapter.Fill(this.DataSet);
            object temp = this.SqlDataAdapter.SelectCommand.Parameters["@output"].Value;
            this.Dispose();
            if (temp is int)
            {
                return (int)temp;
            }
            return int.MinValue;
        }

        public void AccountNew(Account Account)
        {
            if (!Account.Valid)
            {
                throw new ArgumentException();
            }
            this.Initialize(DomainResource.ProcedureAccountNew);
            this.SqlDataAdapter.SelectCommand.Parameters.Add(new SqlParameter(DomainResource.ParameterNameFirst, SqlDbType.VarChar, 50));
            this.SqlDataAdapter.SelectCommand.Parameters[DomainResource.ParameterNameFirst].Value = Account.NameFirst;
            this.SqlDataAdapter.SelectCommand.Parameters.Add(new SqlParameter(DomainResource.ParameterNameLast, SqlDbType.VarChar, 50));
            this.SqlDataAdapter.SelectCommand.Parameters[DomainResource.ParameterNameLast].Value = Account.NameLast;
            this.SqlDataAdapter.SelectCommand.Parameters.Add(new SqlParameter(DomainResource.ParameterNameDisplay, SqlDbType.VarChar, 100));
            this.SqlDataAdapter.SelectCommand.Parameters[DomainResource.ParameterNameDisplay].Value = Account.NameDisplay;
            this.SqlDataAdapter.SelectCommand.Parameters.Add(new SqlParameter(DomainResource.ParameterLogin, SqlDbType.VarChar, 50));
            this.SqlDataAdapter.SelectCommand.Parameters[DomainResource.ParameterLogin].Value = Account.Login;
            this.SqlDataAdapter.SelectCommand.Parameters.Add(new SqlParameter(DomainResource.ParameterPassword, SqlDbType.VarChar, 255));
            this.SqlDataAdapter.SelectCommand.Parameters[DomainResource.ParameterPassword].Value = Account.Password;
            this.SqlDataAdapter.SelectCommand.Parameters.Add(new SqlParameter(DomainResource.ParameterPIN, SqlDbType.Int));
            this.SqlDataAdapter.SelectCommand.Parameters[DomainResource.ParameterPIN].Value = Account.PIN;
            this.SqlDataAdapter.SelectCommand.Parameters.Add(new SqlParameter(DomainResource.ParameterEmail, SqlDbType.VarChar, 255));
            this.SqlDataAdapter.SelectCommand.Parameters[DomainResource.ParameterEmail].Value = Account.Email;
            this.SqlDataAdapter.SelectCommand.Parameters[DomainResource.ParameterGuid].Direction = ParameterDirection.Output;
            this.SqlDataAdapter.SelectCommand.Parameters[DomainResource.ParameterToken].Direction = ParameterDirection.Output;
            this.SqlDataAdapter.Fill(this.DataSet);
            Guid Guid;
            Guid Token;
            if (Guid.TryParse(this.SqlDataAdapter.SelectCommand.Parameters[DomainResource.ParameterGuid].Value.ToString(), out Guid))
            {

            }
            if (Guid.TryParse(this.SqlDataAdapter.SelectCommand.Parameters[DomainResource.ParameterToken].Value.ToString(), out Token))
            {

            }
            this.Dispose();
            
        }
    }
}
